<?php


use Phinx\Seed\AbstractSeed;

class AdminConfigSeed extends AbstractSeed
{
    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        // vendor/bin/phinx seed:run -s AdminConfigSeed
        $model  = $this->table('admin_config');
        $fields = ['title', 'content', 'remark'];
        $values = [
            ['website', 'MyAdmin', '网站名称'],
            ['bei_an', '-', '备案号'],
            ['copyright', 'my-admin', '版权信息'],
            ['watermark_switch', '0', '版权水印'],
        ];

        $insert = [];
        $count = count($fields);
        foreach ($values as $key => $val) {
            for($i=0; $i<$count; $i++){
                $insert[$key][$fields[$i]] = $val[$i];
            }
        }
        if (empty($insert)) return false;

        $model->truncate();
        $model->insert($insert)->saveData();
    }
}
